<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{log_name} : {log_account_no}</title>
<link rel="shortcut icon" href="{dir_image}favicon.ico">
<link rel="stylesheet" type="text/css" href="{dir_css}Global.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Popup.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Dean.css" />

<script type="text/javascript" src="{dir_js}jquery.min.js"></script>
<script type="text/javascript" src="{dir_js}Global.js"></script>



</head>
<body>
<!-- POPUP -->{page_popup}<!-- POPUP END -->
<!-- TOP HEADER -->{page_header}<!-- TOP HEADER END -->
	<div class="main-content">
	
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr valign="top" align="left">
				<td width="220">
					{dean_sub_menu}
				</td>
				<td width="755">
					<div class="page-sub-content">
					<div class="float-right-back"><a href="?page=Subject&cid={course_id}"><img src="{dir_image}icon/back.png" border="0"/></a></div>
					<div class="ann-top-label">{semester_label}</div>
						<input type="hidden" id="sem_linker_id" value="{sem_linker_id}"/>
						<input type="hidden" id="course_id" value="{course_id}"/>
						<form method="post" enctype="multipart/form-data" action="">
							<table width="" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td height="30" width="150">Subject Description<span class="required-field">*</span></td>
									<td width="13">:</td>
									<td width="607"><input type="text" name="txtdesc" class="announce-text-input" value="{txtdesc}"/> <span class="required-field">{w_txtdesc}</span></td>
								</tr>
								<tr>
									<td height="32">Subject Code<span class="required-field">*</span></td>
									<td>:</td>
									<td><input type="text" name="txtcode" class="course-text-input" value="{txtcode}"/> <span class="required-field">{w_txtcode}</span></td>
								</tr>
								<tr>
									<td height="32"></td>
									<td></td>
									<td><input type="hidden" id="txtsaturday" name="txtsaturday" value="Y"/>
										<label for="saturday" class="cursor-pointer">
											<input type="checkbox" id="saturday" name="saturday" onclick="isSaturday();" {saturday}/> <span class="required-field-blue">Saturday Class?</span>
										</label>
									</td>
								</tr>
								<tr><td height="15" colspan="3"><div class="subj-td-cols-line"></div></td></tr>
								
								<tr>
									<td height="32">LECTURE UNITS<span class="required-field">*</span></td>
									<td>:</td>
									<td><input type="text" name="txtlec" id="txtlec" class="subj-text-input" value="{txtlec}" onblur="unitCompute();" onkeypress="return numberDate(event, false);" maxlength="2"/></td>
								</tr>
								<tr>
									<td height="32">LABORATORY UNITS<span class="required-field">*</span></td>
									<td>:</td>
									<td><input type="text" name="txtlab" id="txtlab" class="subj-text-input" value="{txtlab}" onblur="unitCompute();" onkeypress="return numberDate(event, false);" maxlength="2"/></td>
								</tr>
								<tr>
									<td height="32">LEC/LAB UNITS<span class="required-field">*</span></td>
									<td>:</td>
									<td><input type="text" name="txtleclab" id="txtleclab" class="subj-text-input" value="{txtleclab}" onblur="unitCompute();" onkeypress="return numberDate(event, false);" maxlength="2"/></td>
								</tr>
								<tr>
									<td height="32"><strong>TOTAL UNITS</strong></td>
									<td>:</td>
									<td>
										<input type="hidden" name="txttotal" id="txttotal" value="{txttotal}"/>
										<input type="text" name="txttotalparenthesis" id="txttotalparenthesis" class="subj-text-input-dis" value="0" readonly="readonly"/>&nbsp;&nbsp;&nbsp;&nbsp;
										<label for="parenthesis" class="cursor-pointer">
											<input type="checkbox" id="parenthesis" name="txtparenthesis" onclick="totalParenthesis();" {txtchecked}/> <span class="required-field-blue">This is NOT included in total subject unit.</span>
										</label>
									</td>
								</tr>
								
								<tr><td height="15" colspan="3"><div class="subj-td-cols-line"></div></td></tr>
								
								<tr>
									<td height="32"><strong>Co-REQUISITE</strong></td>
									<td>:</td>
									<td valign="middle">
										<input type="text" name="txtco" id="txtco" class="subj-req-text" value="{txtco}" readonly="readonly" onclick="coRequisite();"/>
										<img src="{dir_image}icon/add.png" border="0" onclick="coRequisite();" class="cursor-pointer"/>
										<img src="{dir_image}icon/reset.png" border="0"  onclick="coRequisiteReset();" class="cursor-pointer"/>
									</td>
								</tr>
								<tr id="co_requisite">
									<td colspan="2"></td>
									<td>
										<div class="requisite-popup requisite-popup-width display-none" id="co_requisite_popup">
											<div id="co_requisite_div"></div>
										</div>
									</td>
								</tr>
								<tr>
									<td height="32"><strong>Pre-REQUISITE</strong></td>
									<td>:</td>
									<td valign="middle">
										<input type="text" name="txtpre" id="txtpre" class="subj-req-text" value="{txtpre}" readonly="readonly" onclick="preRequisite();"/>
										<img src="{dir_image}icon/add.png" border="0" onclick="preRequisite();" class="cursor-pointer"/>
										<img src="{dir_image}icon/reset.png" border="0"  onclick="preRequisiteReset();" class="cursor-pointer"/>
									</td>
								</tr>
								<tr id="pre_requisite">
									<td colspan="2"></td>
									<td>
										<div class="requisite-popup requisite-popup-width display-none" id="pre_requisite_popup">
											<div id="pre_requisite_div"></div>
										</div>
									</td>
								</tr>
								
								<tr><td height="15" colspan="3"><div class="subj-td-cols-line"></div></td></tr>
								
								<tr>
									<td height="32"><strong>TOTAL HOURS/WEEK</strong></td>
									<td>:</td>
									<td>
										<input type="text" name="txthrs" id="txthrs" class="subj-text-input" value="{txthrs}" onkeypress="return numberDate(event, false);" maxlength="3"/>
									</td>
								</tr>
								
								<tr><td height="15" colspan="3"><div class="subj-td-cols-line"></div></td></tr>
								<tr>
									<td height="79" colspan="2"></td>
									<td><input type="submit" name="subButton" class="submit-input" value="Save"/> <input type="button" onclick="linkNewPage('Subject&cid={course_id}')" class="submit-input" value="Cancel"/></td>
								</tr>
							</table>
						</form>
					</div>
				</td>
			</tr>
		</table>
		
	</div>
<!-- FOOTER -->{page_footer}<!-- FOOTER -->
<script type="text/javascript">
	
	$(document).ready(function() {
		unitCompute();
		totalParenthesis();
		isSaturday();
	});
	
	function isSaturday() {
		var txtsaturday = $('#txtsaturday');
		if ( $('#saturday').is(':checked') == true )
			txtsaturday.val('Y');
		else
			txtsaturday.val('N');
	}
	
	function totalParenthesis() {
		var txttotalparenthesis = $('#txttotalparenthesis');
		if ( $('#parenthesis').is(':checked') == true )
			txttotalparenthesis.val('(' + txttotalparenthesis.val() + ')');
		else
			txttotalparenthesis.val($('#txttotal').val());
	}
	
	function unitCompute() {
		
		var lec 	= $('#txtlec').val();
		var lab		= $('#txtlab').val();
		var leclab	= $('#txtleclab').val();
		var total = parseInt(lec) + parseInt(lab) + parseInt(leclab);
		if (is_int(total) == true) {
			$('#txttotal').val(total);
			$('#txttotalparenthesis').val(total);
			$('#txthrs').val(total);
		}
		else {
			$('#txttotalparenthesis').val(0);
			$('#txttotal').val(0);
			$('#txthrs').val(0);
		}
	}
	
	function findValue(key, array) {
		// The variable results needs var in this case (without 'var' a global variable is created)
		var results = [];
		for (var i = 0; i < array.length; i++) {
			if (array[i].indexOf(key) == 0) {
				results.push(array[i]);
			}
		}
		return results;
	}
	
	/* CO REQUISITE */
		function coRequisite() {
			
			strArray = $('#txtco').val().split(', ');
		
			var co_requisite_div = $('#co_requisite_div');

			co_requisite_div.html('');
			var sem_linker_id = $('#sem_linker_id').val();
			$.post('request.php', {AJAXPost:'coRequisite', strSubjLinkerID:sem_linker_id}, function(res) {
				if (res == 0) {
					co_requisite_div.append('<div>No Record Found.</div>');
				}
				else {
					co_requisite_div.append('<div class="requisite-hide" onclick="hideCoRequisite();"><img src="./application/images/icon/arrow_up.png" border="0" /></div>');
					$.each( res, function( key, value ) {
						
						var findValueStr = findValue(value['subj_code'], strArray);
						
						if (findValueStr != '')
							onChecked = 'checked="checked"';
						else
							onChecked = '';
						
						co_requisite_div.append('<div class="position-relative"><label for="co_requisite_check' + value['subj_idPK'] + '"  id="co_requisite_label">'+
													'<input type="checkbox" id="co_requisite_check' + value['subj_idPK'] + '" onclick="coRequisiteValue(\'' + value['subj_idPK'] +'\', \'' + value['subj_code'] + '\')" ' + onChecked + '/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')'+
												'</label></div>');
					});
				}
				$('#co_requisite_popup').slideDown();
			}, 'json');
			
		}
		
		function coRequisiteValue(strID, strValue) {
			var txtco = $('#txtco');
			
			if (txtco.val() == '') 
				txtco.val(strValue);	// Auto Add Value
			else
				txtco.val(txtco.val() + ', ' + strValue);
				
			strArray = txtco.val().split(', ');			// Split to Array
			if ( $('#co_requisite_check'+strID).is(':checked') == true )
				$('#txtco').val(strArray.join(", "));	// Combine Array
			else {
				arr = $.grep(strArray, function(n, i){	// Remove item on array
					return (n != strValue);
				});
				txtco.val(arr.join(", "));				// Combine Array
			}
		}
			
			function coRequisiteReset() {
				$('#txtco').val('');
				$('#co_requisite_popup').slideUp();
			}
					
		function hideCoRequisite() {
			$('#co_requisite_popup').slideUp();
		}
	/* CO REQUISITE */
	
	/* PRE REQUISITE */
		function preRequisite() {
			
			var pre_requisite_div = $('#pre_requisite_div');
			pre_requisite_div.html('');
			var course_id = $('#course_id').val();
			$.post('request.php', {AJAXPost:'preRequisite', strCourseID:course_id}, function(res) {
				$.each( res, function( key, value ) {
						pre_requisite_div.append('<div class="ajax-semester">'+
													'<input type="hidden" class="pre_requisite_check" id="pre_requisite_check' + value['sem_linker_idPK'] + '" value="0"/>' +
													'<div id="pre_requisite_click' + value['sem_linker_idPK'] +'" onclick="preRequisiteValue(\'' + value['sem_linker_idPK'] +'\')" class="cursor-pointer"><img src="./application/images/icon/down.png" border="0" /> ' + value['sem_desc'] + '</div>' +
													'<div class="requisite-popup-ajax display-none" id="pre_ajax_requisite_popup' + value['sem_linker_idPK'] +'">' +
														'<div id="pre_ajax_requisite_div' + value['sem_linker_idPK'] +'"></div>' +
													 '</div>' +
												'</div>');
				});
				
			
				strArrayPre = $('#txtpre').val().split(', ');
				
				var findValueStr3rdYr = findValue('3rdYr', strArrayPre);
				if (findValueStr3rdYr != '')
					onChecked3rdYr = 'checked="checked"';
				else
					onChecked3rdYr = '';
				
				pre_requisite_div.append('<div class="ajax-semester"><label for="pre_ajax_requisite_check3Yr"  id="pre_ajax_requisite_label">'+
											'<input type="checkbox" id="pre_ajax_requisite_check3Yr" onclick="preAjaxRequisiteValue(\'3Yr\', \'3rdYr\')" ' + onChecked3rdYr + '/> 3rd Yr. Standing (3rdYr)'+
										 '</label></div>');
				
				var findValueStr4thYr = findValue('4thYr', strArrayPre);
				if (findValueStr4thYr != '')
					onChecked4thYr = 'checked="checked"';
				else
					onChecked4thYr = '';
					
				pre_requisite_div.append('<div class="ajax-semester"><label for="pre_ajax_requisite_check4Yr"  id="pre_ajax_requisite_label">'+
											'<input type="checkbox" id="pre_ajax_requisite_check4Yr" onclick="preAjaxRequisiteValue(\'4Yr\', \'4thYr\')" ' + onChecked4thYr + '/> 4rd Yr. Standing (4thYr)'+
										 '</label></div>');
																	 
				$('#pre_requisite_popup').slideDown();
			}, 'json');
			
		}
			
			function preRequisiteValue(SLID) {
			
				strArray = $('#txtpre').val().split(', ');
			
					$('#pre_ajax_requisite_div'+SLID).html('');
					var sem_linker_id = $('#sem_linker_id').val();
					$.post('request.php', {AJAXPost:'coRequisite', strSubjLinkerID:SLID}, function(res) {
						if ( res == 0 ) {
							$('#pre_ajax_requisite_div'+SLID).append('<div class="ajax-semester-value" onclick="NoRecordFoundClose(\'' + SLID +'\')"><img src="./application/images/icon/close.png" border="0"/> No Record Found.</div>');
						}
						else {
							
							$('#pre_ajax_requisite_div'+SLID).append('<div class="requisite-hide-handle"><div class="requisite-hide" onclick="hidePreRequisite(\'' + SLID +'\');"><img src="./application/images/icon/arrow_up.png" border="0" /></div></div>');
							
							$.each( res, function( key, value ) {
							
							var findValueStr = findValue(value['subj_code'], strArray);
							
							if (findValueStr != '')
								onChecked = 'checked="checked"';
							else
								onChecked = '';
							
								$('#pre_ajax_requisite_div'+SLID).append('<div class="ajax-semester-value"><label for="pre_ajax_requisite_check' + value['subj_idPK'] + '"  id="pre_ajax_requisite_label">'+
																			'<input type="checkbox" id="pre_ajax_requisite_check' + value['subj_idPK'] + '" onclick="preAjaxRequisiteValue(\'' + value['subj_idPK'] +'\', \'' + value['subj_code'] + '\')" ' + onChecked + '/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')'+
																		'</label></div>');
							});
						}
						$('#pre_requisite_check'+SLID).val(1);
						$('#pre_ajax_requisite_popup'+SLID).slideDown();
					}, 'json');
				
			}
				function preAjaxRequisiteValue(strID, strValue) {
					var txtpre = $('#txtpre');
					
					if (txtpre.val() == '') 
						txtpre.val(strValue);	// Auto Add Value
					else
						txtpre.val(txtpre.val() + ', ' + strValue);
				
					strArray = txtpre.val().split(', ');			// Split to Array
					if ( $('#pre_ajax_requisite_check'+strID).is(':checked') == true )
						$('#txtpre').val(strArray.join(", "));	// Combine Array
					else {
						arr = $.grep(strArray, function(n, i){	// Remove item on array
							return (n != strValue);
						});
						txtpre.val(arr.join(", "));				// Combine Array
					}
				}
					function NoRecordFoundClose(SLID) {
						$('#pre_ajax_requisite_div'+SLID).html('');
						$('#pre_requisite_check'+SLID).val(0);
					}
					
					function preRequisiteReset() {
						$('#txtpre').val('');
						$('#pre_requisite_popup').slideUp();
						$('.pre_requisite_check').val(0);
					}
					
		function hidePreRequisite(SLID) {
			$('#pre_ajax_requisite_popup'+SLID).slideUp();
		}
		
</script>
</body>
</html>
